﻿namespace Algoritmia.Problems.Fibonacci
{
    public class SpaceSavingFibonacciNumbers2 : IFibonacciNumbers
    {
        #region Implementation of IFibonacciNumbers

        public int Number(int n)
        {
            if ( n <= 1)
            {
                return n;
            }
            var prev = 0;
            var curr = 1;
            for(int i = 2; i <= n; i++)
            {
                var aux = prev + curr;
                prev = curr;
                curr = aux;
            }
            return curr;
        }

        #endregion
    }
}
